#include "CLocalObject.h"
#include "clcomidfactory.h"
#include "clcomfuncs.h"


CLocalObject::CLocalObject(CLComString id)
{
    m_name = "";
	m_bRdyExit = false;

	SetType(COMM_OBJECT_TYPE_OBJECT);
	if (id.GetLength() > 0)
	{
		SetID(id);
	}
	else
	{
		GenerateGlobalID();
	}
}

CLocalObject::~CLocalObject()
{
}

COMM_OBJECT_TYPE CLocalObject::GetType()
{
	return m_eType;
}
CLComString CLocalObject::GetID()
{
	return m_ID;
}
CLComString CLocalObject::GetID() const
{
	return m_ID;
}
void CLocalObject::SetID(CLComString id)
{
	m_ID = id;
}
void CLocalObject::SetName(CLComString name)
{
    m_name = name;
}
void CLocalObject::SetWantExit()
{
	EnterSection();

	m_bRdyExit = true;

	LeaveSection();
}
bool CLocalObject::BWantExit()
{
	return m_bRdyExit;
}

CLComString CLocalObject::CreatePath(CLComString pathName, CLComString cateName)
{
	if (pathName.GetLength() > 0)
	{
		pathName += "\\";
		pathName += cateName.GetLength() > 0 ? cateName : GetID();
		pathName += "\\";

        CLComFuncs::Make_dir(pathName);
	}
	return pathName;
}

void CLocalObject::SetType(COMM_OBJECT_TYPE type)
{
	m_eType = type;
}
int CLocalObject::Init()
{
	return ELOCALOBJECT_RETURN_VALUE_OK;
}
void CLocalObject::EnterSection()
{
    m_lockSetion.lock();
}
void CLocalObject::LeaveSection()
{
    m_lockSetion.unlock();
}
void CLocalObject::GenerateGlobalID()
{
    m_ID = CLComIDFactory::CreateID();
}
